package com.ews.onlineexchange.controller.assess;

import java.util.List;

import javax.enterprise.inject.Model;
import javax.faces.view.ViewScoped;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.apache.commons.lang3.StringUtils;
import com.ews.onlineexchange.model.DataEntity;
import com.ews.onlineexchange.model.assess.AssessClass;
import com.ews.onlineexchange.service.EntityQuery;

@ViewScoped
@Model
public class AssessClassList extends EntityQuery<AssessClass> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private String name;

	@Override
	protected List<Predicate> getRestrictions(CriteriaBuilder cb, Root<AssessClass> entity) {
		List<Predicate> restrictions = super.getRestrictions(cb, entity);
		restrictions.add(cb.equal(entity.get("delFlag"), DataEntity.DEL_FLAG_NORMAL));
		if (!StringUtils.isBlank(name))
			restrictions.add(cb.like(entity.get("name"),getStringRestriction(name)));
		return restrictions;
	}

	public AssessClassList() {
		setMaxResults(null);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	

}
